package fr.emn.fil.soc.gr3.views;

import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import fr.emn.fil.soc.gr3.controllers.DialogConnexionController;
import fr.emn.fil.soc.gr3.controllers.enums.EnumDialogConnexionController;

public class DialogConnexion extends JDialog {

	private static final long serialVersionUID = -3283836316262882270L;

	private MainFrame parent;
	private JTextField textField_login;
	private JPasswordField textField_password;
	private JLabel lblConnexion = new JLabel("Connexion");
	private JLabel lblLogin = new JLabel("Login :");
	private JLabel lblMotDePasse = new JLabel("Mot de passe  :");
	private JButton btnAnnuler = new JButton("Annuler");
	private JButton btnConnexion = new JButton("Connexion");
	
	public DialogConnexion(MainFrame pparent) {
		super(pparent,"Connexion",true);
		parent = pparent;
		

		setSize(272, 175);
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
		
		lblConnexion.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblConnexion.setBounds(91, 11, 134, 14);
		getContentPane().add(lblConnexion);
		
		textField_login = new JTextField();
		textField_login.setBounds(96, 36, 150, 20);
		getContentPane().add(textField_login);
		textField_login.setColumns(10);
		
		textField_password = new JPasswordField();
		textField_password.setBounds(96, 67, 150, 20);
		getContentPane().add(textField_password);
		textField_password.setColumns(10);
		
		lblLogin.setBounds(10, 39, 76, 14);
		getContentPane().add(lblLogin);
		
		lblMotDePasse.setBounds(10, 70, 86, 14);
		getContentPane().add(lblMotDePasse);
		
		btnAnnuler.setBounds(157, 102, 89, 23);
		getContentPane().add(btnAnnuler);
		
		btnConnexion.setBounds(58, 102, 89, 23);
		getContentPane().add(btnConnexion);
		
		setActions();
	}
	
	private void setActions() {
		btnConnexion.addActionListener(new DialogConnexionController(this, EnumDialogConnexionController.BTN_OK));
		
	}

	public void showDialog(){
		this.textField_login.setText("");
		this.textField_password.setText("");
		getRootPane().setDefaultButton(btnConnexion);
		this.setVisible(true);
	}

	public MainFrame getParent() {
		return parent;
	}

	public JTextField getTextField_login() {
		return textField_login;
	}

	public JPasswordField getTextField_password() {
		return textField_password;
	}

	public JButton getBtnAnnuler() {
		return btnAnnuler;
	}

	public JButton getBtnConnexion() {
		return btnConnexion;
	}
}
